package com.api.workflow.web;


import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.common.util.string.StringUtil;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @author wanghan
 * @version 1.0
 * @Description 应付账款冻结
 * @since 2025/2/27 12:29
 */
public class ContractTriggersProcurementAction extends BaseBean implements Action {


    @Override
    public String execute(RequestInfo requestInfo) {
        try {
            writeLog("start------------------------ContractTriggersProcurementAction");
            //获得流程id
            String workflowid = requestInfo.getWorkflowid();
            //获取表id
            String requestid = requestInfo.getRequestid();
            writeLog("start------------------------ContractTriggersProcurementAction" + requestid);
            RecordSet rs = new RecordSet();
            rs.execute("select tablename from workflow_base a,workflow_bill b where a.formid=b.id and a.id=" + workflowid);
            rs.next();
            //获取主表名
            String maintable = Util.null2String(rs.getString("tablename"));

            //根据表id和主表名查找主表的相关信息
            rs.executeQuery("select * from " + maintable + " where requestid=?", new Object[]{requestid});
            rs.next();
            String zblcid = Util.null2String(rs.getString("zblcid"));//
            String cgddhtbh = Util.null2String(rs.getString("cgddhtbh"));//
            writeLog(zblcid + "--------zblcid");
            if (!StringUtil.isNullOrEmpty(zblcid)) {
                rs.executeQuery("SELECT workflowid FROM workflow_requestbase WHERE requestid = ?", zblcid);
                rs.next();
                String workflowid1 = Util.null2String(rs.getString("workflowid"));
                writeLog(workflowid1 + "--------workflowid1");
                rs.execute("select tablename from workflow_base a,workflow_bill b where a.formid=b.id and a.id=" + workflowid1);
                rs.next();
                //获取主表名
                String mainmaintable = Util.null2String(rs.getString("tablename"));
                writeLog(mainmaintable + "--------mainmaintable");
                boolean b = rs.executeUpdate("update " + mainmaintable + " set hcbs=1 , hth  =  '" + cgddhtbh + "' where requestid=?", zblcid);
                if (b) {
                    return Action.SUCCESS;
                } else {
                    requestInfo.getRequestManager().setMessagecontent("更新主流程状态失败!");
                    return Action.FAILURE_AND_CONTINUE;
                }

            }
            return Action.SUCCESS;

        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessagecontent("接口出错,请联系管理员!" + e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
